<template>
	<view class="lease_restitution">
		<view class="container mt20">
			<lease-order-goods :image="orderDetail.lease_goods_info.image">
				<template #name>{{ orderDetail.goods_name }}</template>
				<!-- <template #name>{{ orderDetail.goods_name }}</template> -->
				<template #specs>
					<text class="mr10">规格：租完可还/买断</text>
					<!-- <text>{{item.order_goods.goods_item_str}}{{ getPeriodsUnit(item.periods_attribute) }}</text> -->
					<text>{{orderDetail.lease_goods_item_str}}</text>
				</template>
				<template #tenancy>
					<text class="mr10">租期：</text>
					<text>{{orderDetail.lease_start_date}}至{{orderDetail.lease_end_date}}</text>
				</template>
				<template #num>
					<text class="mr10">数量：</text>
					<text>{{orderDetail.goods_num}}</text>
				</template>
			</lease-order-goods>
		</view>
		<view class="container mt40">
			<view class="relet-title mt10 mb30">
				租期
			</view>
			<view class="relet-contents">
				<view class="relet-btn" v-for="(item,index) in periods_info" :key="index"
					:class="[index===ischeck?'check-btn':'relet-btn']" @click="btnTime(item,index)">
					{{item.name}}
				</view>
			</view>
		</view>
		<view class="card-button row-between">
			<view class="meney-all" v-if="allmeney!=''">
				共计 <text>￥</text><text>{{allmeney}}</text>
			</view>
			<u-button style="flex: 1;" type="primary" :custom-style="customStyle"  shape="circle" @click="confirmReturn">确认续租</u-button>
		</view>
		<!-- 确认续租弹框 -->
		<u-modal v-model="showConfim" title='续租' :content="content" @confirm="confirm" show-cancel-button=true @cancel="showConfim=false"></u-modal>
	</view>
</template>

<script>
	import {
		orederRelet
	} from '@/api/lease.js'
	export default {
		data() {
			return {
				reletId: 0, //续租订单id
				orderDetail: {},
				periods_info: [], //续期时间列表
				ischeck: '',
				allmeney: '',
				periods_id: '',
				showConfim:false,
				content:'确认将订单续租：',
				customStyle:{
					width:'100%'
				}
			}
		},

		methods: {
			// 初始化数据
			indata() {
				orederRelet({
					action: 'info',
					id: this.reletId
				}).then(res => {
					if (res.code != 1) return;
					this.orderDetail = res.data.goods_info;
					this.periods_info = res.data.periods_info;

				})
			},
			btnTime(item, index) {
				this.ischeck = index;
				this.allmeney = (Number(item.day) * Number(item.rent)).toFixed(2);
				this.periods_id = item.periods_id;
				this.content='确认将订单续租：'
				this.content+=item.name;
			},
        
		 
			//确认续租
			confirmReturn() {
				if (this.allmeney == '') {
					this.$toast({
						title: '请选择租期天数！',
						icon: 'none'
					});
					return;
				}
			
				this.showConfim=true;
				
				
			},
			confirm(){
				uni.showLoading({
					title: '正在提交...',
					mask: true
				});
				orederRelet({
					action: 'submit',
					id: this.reletId,
					periods_id: this.periods_id
				}).then(res => {
					if (res.code == 1) {
						uni.hideLoading();
						this.showConfim=false;
						this.$toast({
							title: res.msg,
							icon: 'success'
						});
						setTimeout(() => uni.navigateBack(), 500);
						
					}
				
				}).catch(()=>{
					uni.hideLoading();
				})
			}
		},

		onLoad(options) {
			const id = options.id
			this.reletId = id;
		},

		onShow() {
			this.indata()
		}
	}
</script>

<style lang="scss" scoped>
	.lease_restitution {
		padding: 0 20rpx 0 20rpx;
	}

	.container {
		padding: 20rpx;
		margin-bottom: 20rpx;
		border-radius: 14rpx;
		background-color: #FFFFFF;
	}

	.uni-list-cell {
		background-color: #FFFFFF;
		padding: 32rpx 24rpx;
		border-radius: 24rpx;
		font-size: 32rpx;
		font-weight: 500;
	}


	.card-button {
		position: fixed;
		bottom: 0;
		width: 100%;
		background: #ffffff;
		padding: 30rpx;
		z-index: 1000;
		/* 确保不被其他元素覆盖 */
		left: 0;

	}



	.relet-btn:last-child {
		margin-right: 0;
	}

	.relet-title {
		color: #000000e6;
		font-size: 32rpx;
		font-style: normal;
		font-weight: 500;
		line-height: 32rpx;

	}

	.relet-contents {
		display: flex;
		flex-wrap: wrap;
		justify-content: start;
		/* 或者使用 space-between、space-around 等根据需求选择 */
		align-items: center;
		color: #000000e6;

		/* 垂直居中 */
		>view {
			width: 172rpx;
			height: 68rpx;
			text-align: center;
			border-radius: 36rpx;
			line-height: 68rpx;
			font-size: 28rpx;
			font-style: normal;
			margin-right: 30rpx;
			/* 设置按钮间距 */
			margin-bottom: 30rpx;
			/* 如果需要底部也有间距，可以添加此属性 */
		}

		.relet-btn {
			background: #F6F6F8;
			color: #000000e6;
			border: 0;

		}

		.check-btn {
			border: 2rpx solid #2482EE;
			background: #2482ee1a;
			color: #2482eee6;

		}
	}

	.meney-all {
		color: #000000e6;
		font-size: 28rpx;
		font-style: normal;
		font-weight: 500;
		line-height: 28rpx;
		margin-right: 80rpx;


		>text:nth-child(1) {
			color: #e63333;
			font-size: 24rpx;
			margin-left: 8rpx;
		}

		>text:nth-child(2) {
			color: #e63333;
			font-size: 40rpx;
			font-style: normal;
			font-weight: 900;
			line-height: 40rpx;
		}
	}
</style>